//
//  BSAnimationView.m
//  MyReader
//
//  Created by Jin Kelei on 13-5-13.
//  Copyright (c) 2013年 jinkelei. All rights reserved.
//

#import "BSAnimationView.h"

static BSAnimationView *instance = nil;

@implementation BSAnimationView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

+ (void)animationWithMessage:(NSString *)message
                 inView:(UIView *)view
                withDim:(BOOL)isDim
                  isOnlyText:(BOOL)isOnlyText
                withDuration:(CGFloat)duration
{
    if (instance) {
//        [instance hide:YES];
//        [instance removeFromSuperview];
//        [instance release];instance = nil;
        return;
    }
    instance = [[BSAnimationView alloc]initWithView:view];
    instance.labelText = message;
    if (isOnlyText) {
        instance.mode = MBProgressHUDModeText;
    }
    instance.dimBackground = isDim;
    [view addSubview:instance];
    [instance show:YES];
    if (duration > 0) {   
        [instance hide:YES afterDelay:duration];
    }
}

+ (void)stopAnimation
{
    if (!instance) {
        return;
    }
    [instance hide:YES];
    [instance removeFromSuperview];
    [instance release];instance = nil;
}

@end
